<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:action name="header" executeResult="true">
	<s:param name="titles">Quản lý sản phẩm</s:param>
</s:action>
<s:action name="managesidebar" executeResult="true" />

<!-- Center -->
<div id="center_column_des" class="center_column">

<div class="breadcrumb">
	<a href="<s:url action="index"></s:url>">Trang chủ</a><span class="navigation-pipe">&gt;</span><span class="navigation_page">Quản lý sản phẩm</span>
</div>
<div class="buttons" style="padding:10px 0 10px 535px;">
	<a class="button" onclick="insertProduct()">Thêm sản phẩm</a>
</div>
	<s:if test="%{error != ''}" >	
	<div class="error" style="text-align:center;color: #CC0000;"><s:property value="%{error}" /></div>
	<br />
	</s:if>
	<table class="list">
		<thead>
			<tr>
				<td width="1" style="text-align: center;vertical-align:middle;">STT</td>
				<td class="left">Tên sản phẩm</td>
				<td class="left">Danh mục</td>
				<td class="left">Số lượng</td>
				<td class="left">Trang thái</td>
				<td class="right">Chức năng</td>
			</tr>
		</thead>
		<tbody>
		<s:set name="stt" value="0"/>
		<s:set name="allCate" value="allCate"/>
		<s:if test="%{products.size > 0}" >				
			<s:iterator value="products" var="p">
			<s:set name="stt" value="#stt+1"/>
			<tr>
				<td style="text-align: center;"><s:property value="#stt"/></td>
				<td class="left"><s:property value="#p.title"/></td>
				<td class="left"><s:property value="#allCate[#p.category_id]"/></td>
				<td class="center"><s:property value="#p.in_stock"/></td>
				<td class="center">
					<s:if test="%{#p.enabled == 0}" >
						Ẩn
					</s:if>
					<s:else>
						Hiện
					</s:else>
				</td>				
				<td class="right">
					<s:if test="%{#p.enabled == 0}" >
						[<a href="" onclick="actionF(<s:property value="#p.product_id" />,'active');return false;" style="color:#003366;">Hiện</a>] |
					</s:if>
					<s:else>
						[<a href="" onclick="actionF(<s:property value="#p.product_id" />,'inactive');return false;" style="color:#003366;">Ẩn</a>] |
					</s:else>				
					[<a href="" onclick="actionF(<s:property value="#p.product_id" />,'change');return false;" style="color:#003366;">Sửa</a>] | 
					[<a href="" onclick="if(confirm('Bạn có muốn xóa sản phẩm này không?')){actionF(<s:property value="#p.product_id" />,'del');}return false;" style="color:#003366;">Xóa</a>]
				</td>				
			</tr>	
			</s:iterator>
		</s:if>
		<s:else>
			<tr>
				<td colspan="6" style="text-align:center;">Không có sản phẩm nào !</td>
			</tr>
		</s:else>
		</tbody>
	</table>
	${pagination}
	<form action="" method="post" class="std" enctype="multipart/form-data" id="actionF">
		<input type="hidden" value="" name="pid" id="sid" />
		<input type="hidden" value="" name="paction" id="saction" />
		<input type="hidden" value='<s:url action="manageproduct"></s:url>' name="link" />
	</form>
<script type="text/javascript">
function actionF(slideId,action){
	var pidVal = $("#sid");
	var pactionVal = $("#saction");
	var editorVal = $("#actionF");
	var delUrl = '<s:url action="manageproduct"></s:url>';
	var activeUrl = '<s:url action="manageproduct"></s:url>';
	var editUrl = '<s:url action="editproduct"></s:url>';
	pidVal.val(slideId);
	if(action == "del"){
		pactionVal.val("del");
		editorVal.attr("action", delUrl);
	}else if(action == "active" || action == "inactive"){
		pactionVal.val(action);
		editorVal.attr("action", activeUrl);
	}else{
		pactionVal.val("change");
		editorVal.attr("action", editUrl);
	}
	
	editorVal.submit();
}
function insertProduct(){
	location = '<s:url action="addproduct"></s:url>';
}
</script>		
</div>

<s:action name="footer" executeResult="true" />